// let baseUrl = "https://it.jushi.com";
let baseUrl = "http://dev.jushi.com";
let token = null;




export function uniReq(requestBody, callback) {
	uni.request({
		url: `${baseUrl}${requestBody.url}`,
		data: requestBody.data,
		method: requestBody.method,
		header: {
			Authorization: token
		},
		success: (res) => {
			if (res.statusCode == 502) {
				console.log("res---11111----", res.statusCode);
				uni.showToast({
					title: '服务器异常',
					duration: 2000,
					icon: "error"
				});
			}
			callback(res.data)
		},
		fail(err) {

			console.log("err---00000----", err);
		}
	})
}



export default async function request(requestBody, callback) {

	new Promise((resolve, reject) => {

			uni.getStorage({
				key: 'token',
				success(e) {
					console.log("token------", e.data.token)
					token = e.data.token
					resolve()
				},
				fail(e) {
					console.log("fail--------", e)
					uniReq(requestBody, callback)
					// reject()
				}
			})
		}).then((res) => {
			uniReq(requestBody, callback)
		})
		.catch((err) => {
			console.log("err--------", err);
		})

}